﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebService.DAO;
using WebService.VO;

namespace WebService.BUS
{
    public class FavoriteBUS
    {
        FavoriteDAO favoriteDAO;
        public FavoriteBUS()
        {
            favoriteDAO = new FavoriteDAO();
        }

        /// <summary>
        /// get favorite item list by device id
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public DataTable getFavoriteList(DeviceVO device, string lang)
        {
            DataTable dt = favoriteDAO.getFavoriteList(device, lang);
            foreach (DataRow row in dt.Rows)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {


                    dt.Columns[i].ReadOnly = false;

                    if (string.IsNullOrEmpty(row[i].ToString()))
                    {
                        if (dt.Columns[i].DataType == typeof(string))
                            row[i] = "NULL";
                        else if (dt.Columns[i].DataType == typeof(int))
                            row[i] = new int();
                        else if (dt.Columns[i].DataType == typeof(DateTime))
                            row[i] = new DateTime();
                    }
                }
            }
            return dt;
        }

        /// <summary>
        /// check item existing in user favorite item list
        /// </summary>
        /// <param name="favorite"></param>
        /// <returns></returns>
        public bool check(FavoriteVO favorite)
        {
            return favoriteDAO.check(favorite);
        }

        /// <summary>
        /// add item to user favorite list
        /// </summary>
        public void insert(FavoriteVO favorite)
        {
            favoriteDAO.insert(favorite);

        }

        /// <summary>
        /// delete item from user favorite list
        /// </summary>
        public void delete(FavoriteVO favorite)
        {
            favoriteDAO.delete(favorite);
        }
    }
}